package main.java.tmi.ariTransport.web;

import java.sql.SQLException;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import main.java.tmi.ariTransport.service.AirTransportService;
import main.java.tmi.common.service.UserVO;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;


/**
 *  Controller
 *
 * @author min
 * @since 2010. 09. 08.
 */
@Controller
public class AirTransportController {
	
    @Resource(name = "airTransportServiceImpl")
    private AirTransportService airTransportService;
    
    /**
     * The Constructor
     */
    public AirTransportController() {
        //logger = LogFactory.getLog(this.getClass());
    }

    /**
     * 
     * 
     * @param HttpServletResponse response
     * @param ModelMap model
     * @return
     * @throws SQLException
     */
    @RequestMapping("/airTransport")
    public String viewList(HttpServletRequest request, HttpServletResponse response,
    		@RequestParam Map param, ModelMap model) throws SQLException {
        System.out.println("====================================================");
        System.out.println("===============airTransport start=========================");
        System.out.println("====================================================");
        UserVO userInfo = (UserVO) RequestContextHolder.getRequestAttributes().getAttribute("userInfo", RequestAttributes.SCOPE_SESSION);
		model.addAttribute("roleId",userInfo.getRoleId());
        model.addAttribute("ordPseq",param.get("ordPseq"));
        model.addAttribute("ordNo1",param.get("ordNo1"));
        model.addAttribute("ordNo2",param.get("ordNo2"));
        model.addAttribute("clearNo",param.get("clearNo"));
        model.addAttribute("mawb",param.get("mawb"));
        model.addAttribute("hawb",param.get("hawb"));
        return "/tmi/airTransport/airTransport";
    } 
    

    /**
     * 조회
     */
    @RequestMapping("/getAirTransportView")
    public void getAirTransportView(@RequestParam Map param, Model model) throws Exception {
        System.out.println("=======================> getAirTransportView start");

        //저장 완료 후 조회
		model.addAttribute("resultMap",airTransportService.getAirTransportView(param));
		model.addAttribute("resultDetailList",airTransportService.getAirTransportDetailList(param));
    }
    

    /**
     * airTransport SAVE
     */
    @RequestMapping("/saveAirTransport")
    public void saveAirTransport(@RequestParam Map param, Model model , HttpServletRequest request) throws Exception {
    	System.out.println("=======================> saveAirTransport Start");
    	
    	UserVO userInfo = (UserVO) RequestContextHolder.getRequestAttributes().getAttribute("userInfo", RequestAttributes.SCOPE_SESSION);
    	param.put("sesseionId", userInfo.getUserId());
    	System.out.println("sesseionId============> "+userInfo.getUserId());
    	

       	model.addAttribute("result", airTransportService.modifyAirTransport(param , request) );

        //저장 완료 후 조회
    	model.addAttribute("resultMap",airTransportService.getAirTransportView(param));
		model.addAttribute("resultDetailList",airTransportService.getAirTransportDetailList(param));
		model.addAttribute("result",true);
    }
    
    
    /**
    * 삭제
    */
    @RequestMapping("/airTransportDetailUpdate")
    public void airTransportDetailUpdate(@RequestParam Map param, Model model) throws Exception {
        System.out.println("=======================> airTransportDetailUpdate Start");
    	
    	UserVO userInfo = (UserVO) RequestContextHolder.getRequestAttributes().getAttribute("userInfo", RequestAttributes.SCOPE_SESSION);
    	param.put("sesseionId", userInfo.getUserId());
    	
        model.addAttribute("result", airTransportService.airTransportDetailUpdate(param) );
    }
    
    
    @RequestMapping("/deleteDoAir")
    public void deleteDoAir(@RequestParam Map param, Model model , HttpServletRequest request) throws Exception {
    	System.out.println("=======================> deleteDoAir Start");
    	
    	UserVO userInfo = (UserVO) RequestContextHolder.getRequestAttributes().getAttribute("userInfo", RequestAttributes.SCOPE_SESSION);
    	param.put("sesseionId", userInfo.getUserId());
    	
		model.addAttribute("result",airTransportService.deleteDo(param));
    }
    
    
}
